class Solution(object):
    def numSpecial(self, mat):
        m = len(mat)
        n = len(mat[0])
        a_set = set()
        for i in range(m):
            if sum(mat[i]) == 1:
                a_set.add((i))
        ans = 0
        for j in range(n):
            if sum([mat[i][j] for i in range(m)]) == 1:
                t = [mat[i][j] for i in range(m)].index(1)
                if t in a_set:
                    ans += 1
        return ans
